package lew.bing.tom;

import groovy.lang.Script;
import groovy.util.GroovyScriptEngine;
import groovy.util.ResourceException;
import groovy.util.ScriptException;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
public class TestGroovyScript {

    public static void main(String[] args) {
        try {
            log.info("before");
            final GroovyScriptEngine engine = new GroovyScriptEngine("web/groovy");
            log.info("after init");

            final Class aClass = engine.loadScriptByName("sub/test1.groovy");
            log.info("load class");
            Script script = (Script) aClass.newInstance();
            log.info("create instance");
            script.setProperty("aInt", 123);
            log.info("set properties");
            final Object test = script.invokeMethod("test", null);
            log.info("method");
            System.out.println(test);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
